package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.Factor;
import com.ruoyi.system.domain.FactorCategory;
import com.ruoyi.system.domain.FactorItem;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.StrategyBuilder;
import com.ruoyi.system.service.IStrategyBuilderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 策略生成器Controller
 *
 * @author ruoyi
 * @date 2022-01-25
 */
@RestController
@RequestMapping("/system/factorCategory")
public class StrategyBuilderController extends BaseController
{
    @Autowired
    private IStrategyBuilderService strategyBuilderService;

    /**
     * 查询策略生成器列表
     */
    @PreAuthorize("@ss.hasPermi('system:factorCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(StrategyBuilder strategyBuilder)
    {
        startPage();
        List<StrategyBuilder> list = strategyBuilderService.selectStrategyBuilderList(strategyBuilder);
        return getDataTable(list);
    }

    /**
     * 查询因子列表
     */
//    @PreAuthorize("@ss.hasPermi('system:factorCategory:list')")
    @GetMapping("/listFactorItem")
    public TableDataInfo listFactor(StrategyBuilder strategyBuilder)
    {
        List<FactorItem> list = strategyBuilderService.selectFactorItemList(strategyBuilder);
        return getDataTable(list);
    }

    /**
     * 导出策略生成器列表
     */
    @PreAuthorize("@ss.hasPermi('system:factorCategory:export')")
    @Log(title = "策略生成器", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StrategyBuilder strategyBuilder)
    {
        List<StrategyBuilder> list = strategyBuilderService.selectStrategyBuilderList(strategyBuilder);
        ExcelUtil<StrategyBuilder> util = new ExcelUtil<StrategyBuilder>(StrategyBuilder.class);
        util.exportExcel(response, list, "策略生成器数据");
    }

    /**
     * 获取策略生成器详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:factorCategory:query')")
    @GetMapping(value = "/{factorCategoryId}")
    public AjaxResult getInfo(@PathVariable("factorCategoryId") String factorCategoryId)
    {
        return AjaxResult.success(strategyBuilderService.selectStrategyBuilderByFactorCategoryId(factorCategoryId));
    }

    /**
     * 新增策略生成器
     */
    @PreAuthorize("@ss.hasPermi('system:factorCategory:add')")
    @Log(title = "策略生成器", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StrategyBuilder strategyBuilder)
    {
        return toAjax(strategyBuilderService.insertStrategyBuilder(strategyBuilder));
    }

    /**
     * 修改策略生成器
     */
    @PreAuthorize("@ss.hasPermi('system:factorCategory:edit')")
    @Log(title = "策略生成器", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StrategyBuilder strategyBuilder)
    {
        return toAjax(strategyBuilderService.updateStrategyBuilder(strategyBuilder));
    }

    /**
     * 删除策略生成器
     */
    @PreAuthorize("@ss.hasPermi('system:factorCategory:remove')")
    @Log(title = "策略生成器", businessType = BusinessType.DELETE)
	@DeleteMapping("/{factorCategoryIds}")
    public AjaxResult remove(@PathVariable String[] factorCategoryIds)
    {
        return toAjax(strategyBuilderService.deleteStrategyBuilderByFactorCategoryIds(factorCategoryIds));
    }
}
